home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-07-16 | 6.6 KB | 242 lines | [TEXT/CWIE] |
- // ===========================================================================
- // CSelectionDialog.cp ©1995-97 Timo Eloranta All rights reserved.
- // ===========================================================================
-
- #include "CSelectionDialog.h"
- #include "GraphGA_PaneIDs.h"
- #include "CPopulation.h" // AutomSelectionStep
-
- #include <PP_Messages.h>
-
- #include <LCaption.h>
- #include <LGAPushButton.h>
- #include <LGACheckbox.h>
- #include <LGARadioButton.h>
-
- #include "CAGASlider.h"
-
- // ---------------------------------------------------------------------------
- // • CSelectionDialog
- //
- // Called by: URegistrar::CreateObject
- // ---------------------------------------------------------------------------
-
- CSelectionDialog::CSelectionDialog( LStream *inStream )
- : LGADialogBox( inStream )
- {
- }
-
- // ---------------------------------------------------------------------------
- // • InitDialog
- //
- // Called by: CGraphGAApp::ObeyCommand
- // ---------------------------------------------------------------------------
-
- void
- CSelectionDialog::InitDialog()
- {
- mStepCapt = (LCaption *) this -> FindPaneByID( capt_Step );
- mMinCapt = (LCaption *) this -> FindPaneByID( capt_Minimum );
-
- mAutomatic = (LGARadioButton *) this -> FindPaneByID( rbut_Automatic );
- mManual = (LGARadioButton *) this -> FindPaneByID( rbut_Manual );
-
- mFactoryButton = (LGAPushButton *) this -> FindPaneByID( but_FactorySettings );
-
- mElitismBox = (LGACheckbox *) this -> FindPaneByID( cbox_Elitism );
-
- mStepSlider = (CAGASlider *) this -> FindPaneByID( slid_StepSlider );
- mMinSlider = (CAGASlider *) this -> FindPaneByID( slid_MinSlider );
-
- if ( mAutomatic ) mAutomatic -> AddListener( this );
- if ( mManual ) mManual -> AddListener( this );
- if ( mElitismBox ) mElitismBox -> AddListener( this );
- if ( mFactoryButton) mFactoryButton -> AddListener( this );
- if ( mStepSlider ) mStepSlider -> AddListener( this );
- if ( mMinSlider ) mMinSlider -> AddListener( this );
- }
-
- // ---------------------------------------------------------------------------
- // • SetValues
- //
- // Called by: CGraphGAApp::ObeyCommand
- // CSelectionDialog::ListenToMessage
- // ---------------------------------------------------------------------------
-
- void
- CSelectionDialog::SetValues( SSelection &inSelection, Int16 inPopSize )
- {
- mPopSize = inPopSize;
- Int16 theAutoValue;
-
- if ( mMinCapt )
- mMinCapt -> SetValue( inSelection.min );
- if ( mMinSlider )
- mMinSlider -> SetValue( inSelection.min );
-
- if ( mStepSlider )
- mStepSlider -> SetValue( inSelection.step );
-
- if ( inSelection.autom )
- mAutomatic -> SetValue( Button_On );
- else mManual -> SetValue( Button_On );
-
- if ( mStepCapt ) {
- if ( inSelection.autom ) {
- theAutoValue = AutomSelectionStep( inSelection.min, inPopSize );
- mStepCapt -> SetValue( theAutoValue );
- mStepCapt -> Refresh();
- } else
- mStepCapt -> SetValue( inSelection.step );
- }
-
- if ( inSelection.elitism )
- mElitismBox -> SetValue( Button_On );
- else mElitismBox -> SetValue( Button_Off );
- }
-
- // ---------------------------------------------------------------------------
- // • GetValues
- //
- // Called by: CGraphGAApp::SetSelFromDialog
- // CSelectionDialog::AdjustFactoryButton
- // ---------------------------------------------------------------------------
-
- void
- CSelectionDialog::GetValues( SSelection &outSelection )
- {
- if ( mStepCapt )
- outSelection.step = mStepCapt -> GetValue();
- if ( mMinCapt )
- outSelection.min = mMinCapt -> GetValue();
- if ( mAutomatic )
- outSelection.autom = mAutomatic -> GetValue();
- if ( mElitismBox )
- outSelection.elitism = mElitismBox -> GetValue();
- }
-
- // ---------------------------------------------------------------------------
- // • ListenToMessage
- //
- // Called by: LBroadcaster::BroadcastMessage
- // ---------------------------------------------------------------------------
-
- void
- CSelectionDialog::ListenToMessage(
- MessageT inMessage,
- void *ioParam )
- {
- Int16 theAutoValue;
-
- switch ( inMessage ) {
-
- case msg_Automatic:
- if ( (mAutomatic -> GetValue() == Button_On) && mStepCapt ) {
- theAutoValue =
- AutomSelectionStep( mMinCapt -> GetValue(), mPopSize );
- mStepCapt -> SetValue( theAutoValue );
- mStepCapt -> Refresh();
-
- mStepSlider -> Disable(); // 10.04.97
- AdjustFactoryButton();
- }
- break;
-
- case msg_ManualStep:
- if ( (mManual -> GetValue() == Button_On) && mStepCapt ) {
- mStepCapt -> SetValue( mStepSlider -> GetValue() );
- mStepCapt -> Refresh();
-
- mStepSlider -> Enable(); // 10.04.97
- AdjustFactoryButton();
- }
- break;
-
- case msg_Elitism:
- AdjustFactoryButton();
- break;
-
- case msg_StepSlider:
- if ( mStepCapt ) {
- if ( mManual -> GetValue() == Button_Off ) {
- mManual -> SetValue( Button_On );
- }
- mStepCapt -> SetValue( *(Int32 *) ioParam );
- mStepCapt -> Draw(nil);
- AdjustFactoryButton();
- }
- break;
-
- case msg_MinSlider:
- if ( mMinCapt ) {
- mMinCapt -> SetValue( *(Int32 *) ioParam );
- mMinCapt -> Draw(nil);
- if ( (mAutomatic -> GetValue() ) && mStepCapt ) {
- theAutoValue =
- AutomSelectionStep( (*(Int32 *) ioParam), mPopSize );
- if ( theAutoValue != mStepCapt -> GetValue() ) {
- mStepCapt -> SetValue( theAutoValue );
- mStepCapt -> Draw(nil);
- }
- }
- AdjustFactoryButton();
- }
- break;
-
- case msg_FactorySettings:
- SSelection theDefaults = { DEFAULT_SELECTION_STEP,
- DEFAULT_SELECTION_MIN,
- DEFAULT_SELECTION_AUTOM,
- DEFAULT_ELITISM };
- SetValues( theDefaults, mPopSize );
- break;
-
- default:
- LGADialogBox::ListenToMessage( inMessage, ioParam );
- break;
- }
- }
-
- // ---------------------------------------------------------------------------
- // • AdjustFactoryButton (PRIVATE)
- //
- // Called by: CSelectionDialog::ListenToMessage
- // ---------------------------------------------------------------------------
-
- void
- CSelectionDialog::AdjustFactoryButton( )
- {
- SSelection theS;
-
- GetValues( theS );
-
- if ( theS.min == DEFAULT_SELECTION_MIN &&
- theS.autom == DEFAULT_SELECTION_AUTOM &&
- theS.elitism == DEFAULT_ELITISM )
- mFactoryButton -> Disable();
- else
- if ( ! mFactoryButton -> IsEnabled() )
- mFactoryButton -> Enable();
- }
-
- // ---------------------------------------------------------------------------
- // • FindCommandStatus
- //
- // Called by: LCommander::ProcessCommandStatus
- // ---------------------------------------------------------------------------
- // Disable all menu items except for the one which opens the About box.
-
- void
- CSelectionDialog::FindCommandStatus(
- CommandT inCommand,
- Boolean &outEnabled,
- Boolean& /* outUsesMark */,
- Char16& /* outMark */,
- Str255 /* outName */)
- {
- outEnabled = false;
- if (inCommand == cmd_About) {
- outEnabled = true;
- }
- }
-